package com.xucy.springboot.redis.PubSub;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Author xucy
 * @Date 2019-07-04 14:58
 * @Description
 **/

@RestController
@RequestMapping("/listPubSub")
@AutoConfigureAfter(StringRedisTemplate.class)
public class ListPubSub implements CommandLineRunner {
    Logger logger = LoggerFactory.getLogger(ListPubSub.class);

    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    @Override
    public void run(String... args) throws Exception {

//        new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    while(true){
//                        logger.info("等待中");
//                        String listingList = stringRedisTemplate.opsForList().rightPop("listingList", 10, TimeUnit.DAYS);
//                        logger.info("等待结束");
//                        logger.info(listingList);
//                    }
//
//                }
//            }){
//        }.start();
    }

    @RequestMapping("/pushList")
    public String pushList(){
        stringRedisTemplate.opsForList().leftPush("listingList","push进来值了");
        return "成功";
    }

}
